package cc.bukkitPlugin.banitem.check;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import org.bukkit.Material;

public class DamageList implements Cloneable{

    public final Material mMaterial;
    private HashMap<Short,Damage> mDamages=new HashMap<>();

    public DamageList(Material pMaterial){
        this.mMaterial=pMaterial;
    }

    /**
     * 添加一个Damage到Damage列表,保证该实例被使用
     * <p>
     * 如果列表中存在同一个值的Damage,将会尝试合并他们<br />
     * </p>
     * @param pDamage 要添加的Damage
     */
    public void add(Damage pDamage){
        if(pDamage==null)
            return;
        Damage tDamage=this.mDamages.put(pDamage.mValue,pDamage);
        if(tDamage!=null){ // damage已经存在,合并
            if(tDamage==pDamage)
                return;
            for(String sNBTLabelKey : tDamage.getNBTLabelSet())
                pDamage.putNBTValues(sNBTLabelKey,tDamage.getNBTValues(sNBTLabelKey));
        }
    }

    public Set<Short> keySet(){
        Set<Short> set=new HashSet<>();
        set.addAll(this.mDamages.keySet());
        return set;
    }

    public Collection<Damage> values(){
        return this.mDamages.values();
    }

    public Damage get(short pDamage){
        return this.mDamages.get(pDamage);
    }

    public Damage remove(short pDamage){
        return this.mDamages.remove(pDamage);
    }

    public boolean containsKey(short damage){
        return this.mDamages.containsKey(damage);
    }

    public boolean containsValue(Damage pDamage){
        return this.mDamages.containsValue(pDamage);
    }

    public void clear(){
        this.mDamages.clear();
    }

    public boolean isEmpty(){
        return this.mDamages.isEmpty();
    }

}
